//
//  UIImage+expand.m
//  0907-weather
//
//  Created by zhoubaitong on 2017/9/7.
//  Copyright © 2017年 cckv. All rights reserved.
//

#import "UIImage+expand.h"

@implementation UIImage (expand)
- (UIImage *)imageByTintColor:(UIColor *)color {
    
    UIGraphicsBeginImageContextWithOptions(self.size, NO, [UIScreen mainScreen].scale);
    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
    [color set];
    UIRectFill(rect);
    [self drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeDestinationIn alpha:1];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

+ (UIImage *)drawWithTopic:(NSString*)topic{
    
    CGRect rect=CGRectMake(0, 0, 60, 60);
    UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0);
    CGContextRef ref=UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(ref, [UIColor whiteColor].CGColor);
    CGContextFillRect(ref, rect);
    
    NSMutableParagraphStyle * _style=[[NSMutableParagraphStyle alloc]init];
    _style.alignment=NSTextAlignmentCenter;
    _style.lineBreakMode=NSLineBreakByTruncatingTail;
    _style.lineSpacing=10;
    [topic drawInRect:CGRectMake(15, 10, 60, 60) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:40.0f]}];
    UIImage * newImage=UIGraphicsGetImageFromCurrentImageContext();
    return newImage;
}
+ (UIImage *)resizeWithImage:(UIImage *)image{
    CGFloat top = image.size.height/2.0;
    CGFloat left = image.size.width/2.0;
    CGFloat bottom = image.size.height/2.0;
    CGFloat right = image.size.width/2.0;
    return [image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right)resizingMode:UIImageResizingModeStretch];
}

@end
